atspi: Set editable state
authorMatthias Clasen <mclasen@redhat.com>
Sun, 11 Oct 2020 22:59:22 +0000 (18:59 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 12 Oct 2020 19:10:40 +0000 (15:10 -0400)
ATs look at not just the implemented interfaces, but
also the states to decide what to do. It turns out that
the EditableText interface is only used by accerciser
if the editable state is set. So set it.

gtk/a11y/gtkatspicontext.c

index 2600565b99ad4db9201a83c47f992527871ec1d4..332c52c4d7c153efe68c36729936d6a8d3e90390 100644 (file)
 #include "gtkatspiprivate.h"
 #include "gtkatspiutilsprivate.h"
 #include "gtkatspitextprivate.h"
+#include "gtkatspieditabletextprivate.h"
 #include "gtkatspivalueprivate.h"
 
 #include "a11y/atspi/atspi-accessible.h"
 #include "a11y/atspi/atspi-text.h"
+#include "a11y/atspi/atspi-editabletext.h"
 #include "a11y/atspi/atspi-value.h"
 
 #include "gtkdebug.h"
+#include "gtkeditable.h"
 #include "gtkroot.h"
+#include "gtktextview.h"
 #include "gtkwindow.h"
 
 #include <gio/gio.h>
@@ -93,11 +97,20 @@ collect_states (GtkAtSpiContext    *self,
                 GVariantBuilder *builder)
 {
   GtkATContext *ctx = GTK_AT_CONTEXT (self);
+  GtkWidget *widget = GTK_WIDGET (gtk_at_context_get_accessible (ctx));
   GtkAccessibleValue *value;
   guint64 state = 0;
 
   state |= (G_GUINT64_CONSTANT (1) << ATSPI_STATE_VISIBLE);
 
+  if (GTK_IS_EDITABLE (widget) &&
+      gtk_editable_get_editable (GTK_EDITABLE (widget)))
+    state |= (G_GUINT64_CONSTANT (1) << ATSPI_STATE_EDITABLE);
+
+  if (GTK_IS_TEXT_VIEW (widget) &&
+      gtk_text_view_get_editable (GTK_TEXT_VIEW (widget)))
+    state |= (G_GUINT64_CONSTANT (1) << ATSPI_STATE_EDITABLE);
+
   if (gtk_at_context_has_accessible_state (ctx, GTK_ACCESSIBLE_STATE_BUSY))
     {
       value = gtk_at_context_get_accessible_state (ctx, GTK_ACCESSIBLE_STATE_BUSY);
@@ -538,6 +551,18 @@ gtk_at_spi_context_register_object (GtkAtSpiContext *self)
                                          NULL);
     }
 
+  vtable = gtk_atspi_get_editable_text_vtable (widget);
+  if (vtable)
+    {
+      g_variant_builder_add (&interfaces, "s", "org.a11y.atspi.EditableText");
+      g_dbus_connection_register_object (self->connection,
+                                         self->context_path,
+                                         (GDBusInterfaceInfo *) &atspi_editable_text_interface,
+                                         vtable,
+                                         self,
+                                         NULL,
+                                         NULL);
+    }
   vtable = gtk_atspi_get_value_vtable (widget);
   if (vtable)
     {